const mongoose = require('mongoose');
const { dbUri } = require('../config/config.default');
console.log(dbUri);
// 链接 mongodb 数据库
mongoose.connect(dbUri, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
});

const db = mongoose.connection
// 当链接失败的时候
db.on('error', (error) => {
    console.log('数据库链接失败：', error);
})
// 当链接成功的时候
db.on('open', function () {
    console.log('数据库链接成功');
})
// 组织导出模型构造函数
module.exports = {
    User: mongoose.model('User', require('./user')),
    Article: mongoose.model('Article', require('./articles')),
    Profile: mongoose.model('Profile', require('./profiles')),
    Tag: mongoose.model('Tag', require('./tags'))
}
